import request from "@/utils/request";

const BASE_URL = "/api/v1/order/sales/";

const SalesOrderAPI = {
  getInfo(id: string) {
    return request<any, SalesOrderPageQuery>({
      url: `${BASE_URL}${id}/`,
      method: "get",
    });
  },
  getPage(queryParams: SalesOrderPageQuery) {
    return request<any, PageResult<SalesOrderPageVO[]>>({
      url: `${BASE_URL}`,
      method: "get",
      params: queryParams,
    });
  },

  getFormData(id: string) {
    return request<any, SalesOrderForm>({
      url: `${BASE_URL}${id}/`,
      method: "get",
    });
  },
  add(data: SalesOrderForm) {
    return request({
      url: `${BASE_URL}`,
      method: "post",
      data: data,
    });
  },
  update(id: string, data: SalesOrderForm) {
    return request({
      url: `${BASE_URL}${id}/`,
      method: "patch",
      data: data,
    });
  },
  getOptions(query: string) {
    return request<any, OptionType[]>({
      url: `${BASE_URL}options/`,
      method: "get",
      params: {
        search: query,
      },
    });
  },
};
export default SalesOrderAPI;

interface SalesOrderPageQuery extends PageQuery {
  /** 搜索关键字 */
  search?: string;
}

interface SalesOrderForm {
  id?: string;
  order_type?: number; // 订单类型，预测订单，正式订单，加急订单
  customer?: string;
  product?: string;
  quantity?: number;
  unit?: number;
  price?: number;
  // 交货日期
  delivery_date?: Date;
  create_time?: Date;
  update_time?: Date;
  is_update?: boolean;
  status?: number;
  title?: string;
}

interface SalesOrderPageVO {
  id: string;
  order_type_name?: string; // 订单类型，预测订单，正式订单，加急订单
  customer?: string;
  product?: string;
  quantity?: number;
  unit_name?: string;
  price?: number;
  total_price?: number;
  // 交货日期
  delivery_date?: Date;
  title?: string;
  create_time?: Date;
  update_time?: Date;
  is_update?: boolean;
  status?: number;
}
export { SalesOrderPageQuery, SalesOrderForm, SalesOrderPageVO };
